<?php

/**
 * 获取文件夹路径
 * @param  $files 文件名/数组
 * @param $param string 文件夹名称/array 键值对 array('文件夹名称'=>'对应字段')
 * @dep 数组维度
 * @return array|string
 */
function getUploadImgDir($files,$param,$dep = 2) {
    if (empty($files) && $files == '') return;
    if (is_array($files)) {
        if ($dep == 1) {
            foreach ($param as $k=>$v) {
                $url = HTTP_TYPE.$_SERVER['HTTP_HOST'].__ROOT__."/Public/upload/".$k."/";
                $files[$v] = $url.$files[$v];
            }
        } else {
            $count = count($files);
            //二维数组
            for ($i = 0; $i < $count; $i++) {
                foreach ($param as $k=>$v) {
                    $url = HTTP_TYPE.$_SERVER['HTTP_HOST'].__ROOT__."/Public/upload/".$k."/";
                    $files[$i][$v] = $url.$files[$i][$v];
                }
            }
        }
        return $files;
    } else {
        $url = HTTP_TYPE.$_SERVER['HTTP_HOST'].__ROOT__."/Public/upload/".$param."/";
        return $url.$files;
    }
}

function createOrderNO ()
{
    return date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
}

function object_to_array($obj) {
    $obj = $obj;
    foreach ($obj as $k => $v) {
        if (gettype($v) == 'resource') {
            return;
        }
        if (gettype($v) == 'object' || gettype($v) == 'array') {
            $obj[$k] = (array)object_to_array($v);
        }
    }

    return $obj;
}

function array_to_object($arr) {
    if (gettype($arr) != 'array') {
        return;
    }
    foreach ($arr as $k => $v) {
        if (gettype($v) == 'array' || getType($v) == 'object') {
            $arr[$k] = (object)array_to_object($v);
        }
    }

    return (object)$arr;
}